import { DataTypes, Deferrable } from "sequelize/types";
import sequelize from "../db/sequelize";
import Result from "./result.model";
import User from "./user.model";

const Star = sequelize.define('star', {
  resultId: {
    type: DataTypes.INTEGER,
    references: {
      model: Result,
      key: 'id',
    },
    comment: "答案的id"
  },
  userId: {
    type: DataTypes.INTEGER,
    references: {
      model: User,
      key: 'id',
      deferrable: Deferrable.INITIALLY_IMMEDIATE
    },
    comment: "用户的id"
  },
  star: {
    type: DataTypes.INTEGER,
    validate: {
      max: 5,
      min: 0,
    },
    allowNull: false,
    comment: '用户打的星'
  }
})

module.exports = Star
